home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
United Public Domain Gold 2
/
United Public Domain Gold 2.iso
/
utilities
/
pu015.dms
/
pu015.adf
/
StarChart
/
Source
/
star9.c
< prev
next >
Wrap
C/C++ Source or Header
|
1989-09-24
|
15KB
|
487 lines
/*=========================================================================
Star9.c -- This module builds and submits a requester in response to
the user's choice of 'change clock rate' from the OPTIONS menu
of the Star Chart program. The requester lets the user modify the
number of seconds of simulated time that pass for each second of real
time.
Credits for Star Chart:
Robert L. Hill of the Orange County, CA. Amiga Friends User Group
wrote the original version of StarChart in AmigaBasic
The star data and many of the main functions of this
version are derived from that program.
Ray R. Larson wrote the c version 1.0 of StarChart, 'intuitionizing'
and enhancing the speed and functions of the original.
Copyright (c) 1986 by Ray R. Larson
This program may be freely distributed and copied, but may not be sold
without the permission of the author. If you modify or enhance it,
please include the above credits (and please send me a copy!).
Ray R. Larson
6425 Central Ave. #304
El Cerrito, CA 94530
BitNet LARSON@UCBCMSA
=========================================================================*/
/*------------Header file for all of the standard stuff----*/
/*-------------plus definitions of global structures-------*/
#include "star.h"
/**********************************************************************
* Gadget Structure Definitions
*
* The following structures were defined using the Gadget Editor created
* by the Programmer's Network.
* The credits for the Gadget Editor are:
*
* John Draper - Initial design, coordination, and integration.
* Ray Larson - Images and Intuitext.
* Brent Southard - Saving and restoring gadgets in binary form.
* Dave Milligan - Gadget Editor Main menu.
*
*
**********************************************************************/
/* Definitions for Gadget ID numbers */
#define TIMEINTGAD 0
#define WHITEGADGAD 1
#define CANTIMEGAD 2
#define OKTIMEGAD 3
/**********************************************************************
* Text attribute structures used in rendering IntuiTexts
**********************************************************************/
extern struct TextAttr TxtAt_Plain,TxtAt_BIU,TxtAt_BU,TxtAt_BI,TxtAt_B,
TxtAt_IU,TxtAt_I,TxtAt_U;
struct IntuiText Time_Error_Text = {
3, 2, /* FrontPen, BackPen */
JAM2, /* DrawMode */
0, 0, /* LeftEdge, TopEdge */
&TxtAt_B, /* ITextFont Pointer */
/* The IText */
(UBYTE *)"?",
NULL /* NextText */
};
/**********************************************************************
* Border Definitions for TimeReq requester
**********************************************************************/
SHORT TimeReq_Pairs_1[] = {
0, 0,
257, 0,
257, 100,
0, 100,
0, 0
};
struct Border TimeReq_bord_1 = {
1, 1, /* LeftEdge, TopEdge */
7, 1, JAM2, /* FrontPen, BackPen, DrawMode*/
5, /* Count of XY pairs */
(SHORT *)&TimeReq_Pairs_1, /* XY pairs */
NULL /* Next Border */
};
SHORT TimeReq_Pairs_2[] = {
0, 0,
251, 0,
251, 97,
0, 97,
0, 0
};
struct Border TimeReq_bord_2 = {
3, 3, /* LeftEdge, TopEdge */
1, 7, JAM2, /* FrontPen, BackPen, DrawMode*/
5, /* Count of XY pairs */
(SHORT *)&TimeReq_Pairs_2, /* XY pairs */
&TimeReq_bord_1 /* Next Border */
};
/**********************************************************************
* Border Definitions for okTime gadget
**********************************************************************/
SHORT okTime_Pairs_2[] = {
0, 0,
88, 0,
88, 17,
0, 17,
0, 0
};
struct Border okTime_bord_2 = {
-1, -1, /* LeftEdge, TopEdge */
1, 7, JAM2, /* FrontPen, BackPen, DrawMode*/
5, /* Count of XY pairs */
(SHORT *)&okTime_Pairs_2, /* XY pairs */
NULL /* Next Border */
};
/**********************************************************************
* IntuiTexts for the okTime gadget.
**********************************************************************/
struct IntuiText okTime_Text_0 = {
7, 0, /* FrontPen, BackPen */
JAM2, /* DrawMode */
12, 4, /* LeftEdge, TopEdge */
&TxtAt_B, /* ITextFont Pointer */
/* The IText */
(UBYTE *)" OK ",
NULL
};
/**********************************************************************
* Gadget Structure definition for the okTime gadget.
**********************************************************************/
struct Gadget okTime = {
NULL, /* NextGadget pointer */
152, 76, /* LeftEdge, TopEdge */
88, 17, /* Width, Height */
/* Gadget Flags */
GADGHCOMP,
/* Activation Flags */
RELVERIFY | GADGIMMEDIATE,
/* GadgetType */
BOOLGADGET | REQGADGET,
(APTR)&okTime_bord_2, /* GadgetRender */
NULL, /* SelectRender */
&okTime_Text_0, /* GadgetText */
0x0, /* MutualExclude */
NULL, /* SpecialInfo */
OKTIMEGAD, /* GadgetID */
0x1 /* UserData Pointer */
};
/**********************************************************************
* Border Definitions for canTime gadget
**********************************************************************/
SHORT canTime_Pairs_3[] = {
0, 0,
88, 0,
88, 17,
0, 17,
0, 0
};
struct Border canTime_bord_3 = {
-1, -1, /* LeftEdge, TopEdge */
1, 7, JAM2, /* FrontPen, BackPen, DrawMode*/
5, /* Count of XY pairs */
(SHORT *)&canTime_Pairs_3, /* XY pairs */
NULL /* Next Border */
};
/**********************************************************************
* IntuiTexts for the canTime gadget.
**********************************************************************/
struct IntuiText canTime_Text_0 = {
7, 0, /* FrontPen, BackPen */
JAM2, /* DrawMode */
10, 4, /* LeftEdge, TopEdge */
&TxtAt_B, /* ITextFont Pointer */
/* The IText */
(UBYTE *)" CANCEL ",
NULL
};
/**********************************************************************
* Gadget Structure definition for the canTime gadget.
**********************************************************************/
struct Gadget canTime = {
&okTime, /* NextGadget pointer */
29, 76, /* LeftEdge, TopEdge */
88, 17, /* Width, Height */
/* Gadget Flags */
GADGHCOMP,
/* Activation Flags */
RELVERIFY | GADGIMMEDIATE | ENDGADGET,
/* GadgetType */
BOOLGADGET | REQGADGET,
(APTR)&canTime_bord_3, /* GadgetRender */
NULL, /* SelectRender */
&canTime_Text_0, /* GadgetText */
0x0, /* MutualExclude */
NULL, /* SpecialInfo */
CANTIMEGAD, /* GadgetID */
0x1 /* UserData Pointer */
};
/**********************************************************************
* Border Definitions for Timegad gadget
**********************************************************************/
SHORT Timegad_Pairs_5[] = {
0, 0,
73, 0,
73, 9,
0, 9,
0, 0
};
struct Border Timegad_bord_5 = {
-1, -1, /* LeftEdge, TopEdge */
1, 7, JAM2, /* FrontPen, BackPen, DrawMode*/
5, /* Count of XY pairs */
(SHORT *)&Timegad_Pairs_5, /* XY pairs */
NULL /* Next Border */
};
/**********************************************************************
* IntuiTexts for the Timegad gadget.
**********************************************************************/
struct IntuiText Timegad_Text_2 = {
0, 2, /* FrontPen, BackPen */
JAM2, /* DrawMode */
-39, 10, /* LeftEdge, TopEdge */
&TxtAt_I, /* ITextFont Pointer */
/* The IText */
(UBYTE *)" (range 0 - 1800)",
NULL
};
struct IntuiText Timegad_Text_1 = {
1, 2, /* FrontPen, BackPen */
JAM2, /* DrawMode */
-56, -10, /* LeftEdge, TopEdge */
&TxtAt_B, /* ITextFont Pointer */
/* The IText */
(UBYTE *)" per second of real time:",
&Timegad_Text_2 /* NextText */
};
struct IntuiText Timegad_Text_0 = {
1, 2, /* FrontPen, BackPen */
JAM2, /* DrawMode */
-64, -19, /* LeftEdge, TopEdge */
&TxtAt_B, /* ITextFont Pointer */
/* The IText */
(UBYTE *)" Seconds of Simulated Time",
&Timegad_Text_1 /* NextText */
};
/**********************************************************************
* String information for the Timegad string gadget.
**********************************************************************/
UBYTE PlusTimeBuf[12];
UBYTE Timegad_ubuf_2[12];
struct StringInfo PlusTimeTxt = {
PlusTimeBuf, Timegad_ubuf_2, /* Buffer, UndoBuffer */
0, 11, 0, /* BufferPos, MaxChars, DispPos */
0, 0, /* UndoPos, NumChars */
0, 87, 39, /* DispCount, CLeft, CTop */
0x0, 0, /* LayerPtr, LongInt */
0x0 /* AltKeyMap */
};
/**********************************************************************
* Gadget Structure definition for the Timegad gadget.
**********************************************************************/
struct Gadget Timegad = {
&canTime, /* NextGadget pointer */
87, 39, /* LeftEdge, TopEdge */
73, 9, /* Width, Height */
/* Gadget Flags */
GADGHCOMP,
/* Activation Flags */
RELVERIFY | GADGIMMEDIATE | LONGINT | STRINGCENTER,
/* GadgetType */
STRGADGET | REQGADGET,
(APTR)&Timegad_bord_5, /* GadgetRender */
NULL, /* SelectRender */
&Timegad_Text_0, /* GadgetText */
0x0, /* MutualExclude */
(APTR)&PlusTimeTxt, /* SpecialInfo */
TIMEINTGAD, /* GadgetID */
0x1 /* UserData Pointer */
};
/****************************************************************************
* Global Structures
***************************************************************************/
/* the newwindow structure used in GT */
extern struct NewWindow nw;
extern struct Window *w;
extern FLOAT MaxPlus, MaxWhite;
extern SHORT TimeDelay;
/****************************************************************************
* External function definitions
***************************************************************************/
extern struct IntuiMessage *GetMsg();
extern double atof();
/****************************************************************************
* Requester structure and global pointer to it's gadget list.
***************************************************************************/
struct Requester TimeRequester;
/****************************************************************************
* The Code part of the GetTimes module.
***************************************************************************/
GetTimes()
{
BOOL cancelchosen;
LONG iflags;
struct RastPort *reqrp;
SHORT worktimedel;
/* fix the IDCMP flags to report requester set and clear */
iflags = nw.IDCMPFlags;
iflags |= REQCLEAR;
ModifyIDCMP(w,iflags);
/* initialize the times requester */
InitTimeReq();
/* Put up the requester */
Request(&TimeRequester,w);
reqrp = TimeRequester.ReqLayer->rp;
/* let the user fill in the parameters and wait for a cancel or ok. */
worktimedel = TimeDelay;
cancelchosen = WaitTimeReq(reqrp,&worktimedel);
/* if the user cancelled, just return -- otherwise set Time delay */
/* and redisplay the star chart. */
if (cancelchosen) return(0);
TimeDelay = worktimedel;
} /* GetTimes */
/*
* Init the time requester
*/
InitTimeReq()
{
struct RastPort *reqrp;
InitRequester(&TimeRequester);
TimeRequester.LeftEdge = 110;
TimeRequester.TopEdge = 12;
TimeRequester.Width = 260;
TimeRequester.Height = 105;
TimeRequester.ReqGadget = &Timegad;
TimeRequester.ReqText = NULL;
TimeRequester.BackFill = 2;
TimeRequester.Flags = 0;
TimeRequester.ReqBorder = &TimeReq_bord_2;
sprintf(PlusTimeBuf,"%d",TimeDelay);
PlusTimeTxt.NumChars = (LONG)strlen(PlusTimeBuf);
*(Timegad_ubuf_2) = '\0';
}
/****************************************************************************
* WaitTimeReq - permit user to change the values in the integer gadgets
* and check the values they install until either the
* CANCEL gadget is clicked or the OK gadget is clicked AND
* there are no outstanding input errors
***************************************************************************/
BOOL WaitTimeReq(reqrp,worktime)
struct RastPort *reqrp;
SHORT *worktime;
{
ULONG class = GADGETDOWN;
struct IntuiMessage *message;
struct Gadget *gadget;
struct StringInfo *si;
BOOL cancelflag = FALSE;
LONG errorflag = 0L;
while (class != REQCLEAR)
{
if ((message=(struct IntuiMessage *) GetMsg(w->UserPort)) == 0L)
{
Wait(1L<<w->UserPort->mp_SigBit);
continue;
}
class = message->Class;
gadget = (struct Gadget *) message->IAddress;
ReplyMsg(message);
switch (class)
{
case GADGETDOWN:
break;
case GADGETUP:
switch (gadget->GadgetID)
{
case TIMEINTGAD:
si = (struct StringInfo *)gadget->SpecialInfo;
if ((si->LongInt > 1800) || (si->LongInt < 1))
/* put a "?" next to the gadget */
{
errorflag = 1;
DisplayBeep(w->WScreen);
PrintIText(reqrp,&Time_Error_Text,
(LONG)(gadget->LeftEdge - 10),
(LONG)gadget->TopEdge);
}
else
{ /* user must have fixed an error, so turn off the ? */
errorflag = 0;
*worktime = (SHORT)si->LongInt;
Time_Error_Text.FrontPen = 2;
PrintIText(reqrp,&Time_Error_Text,
(LONG)(gadget->LeftEdge - 10),
(LONG)gadget->TopEdge);
Time_Error_Text.FrontPen = 3;
}
break;
case CANTIMEGAD :
cancelflag = TRUE;
break;
case OKTIMEGAD :
if (errorflag == 0)
EndRequest(&TimeRequester,w);
else DisplayBeep(w->WScreen);
break;
} /* end of GADGETUP switch */
} /* end of CLASS switch */
}/* end of while loop */
return(cancelflag);
} /* WaitTimeReq */